package jeecg.mongodb.system;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

public class BeanFactory {
	/**
	 * 根据json字符串创建java对象
	 * @throws ClassNotFoundException 
	 * */
	@SuppressWarnings("unchecked")
	public static DynamicBean createQueryBean(String json){
		HashMap propertyMap=new HashMap();
		JsonParser jp=new JsonParser();
		JsonObject jo=jp.parse(json).getAsJsonObject();
		Set<Map.Entry<String,JsonElement>> set=jo.entrySet();
		try {
			for (Entry<String, JsonElement> entry : set) {
				propertyMap.put(entry.getKey(), Class.forName("java.lang.String"));
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		DynamicBean bean=new DynamicBean(propertyMap);
		for (Entry<String, JsonElement> entry : set) {
			bean.setValue(entry.getKey(), entry.getValue().toString());
		}
		return bean; 
	}
}
